package Multithreading.Exercise001;

/**
 * ClassName:ThreadDome002
 * Package:Multithreading.Exercise
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/3/5-15:56
 * @Version:v1.0
 */
public class ThreadDome002 {
    /*线程的调度
    * 1.抢占式调度：随机性(多个线程抢占CPU的执行权)
    * 2.非抢占式调度：所有线程轮流执行
    * */
    //setPriority(int newPriority) 设置线程的优先级
    //final int getPriority() 获取线程的优先级
    public static void main(String[] args) {
        //创建线程要执行的参数对象
        MyRunnable mr = new MyRunnable();
        //创建线程对象
        Thread t1 = new Thread(mr,"飞机");
        Thread t2 = new Thread(mr,"坦克");
        //优先级越高抢到CPU的概率越高
        t1.setPriority(1);
        t2.setPriority(10);

        t1.start();
        t2.start();
//        System.out.println(t1.getPriority());//5 默认
//        System.out.println(t2.getPriority());//5 默认
//        System.out.println(Thread.currentThread().getPriority());//mian 方法的优先级5


    }
}
